package thread;

public class SyncDemo5 {
    public static void main(String[] args) {
        Coo c = new Coo();
        Thread t1 = new Thread(c::methodA);
        Thread t2 = new Thread(c::methodB);
        t1.start();
        t2.start();
    }
}

class Coo{
    public synchronized void methodA(){
        Thread t = Thread.currentThread();
        System.out.println(t.getName()+"开始执行methodA");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.getName()+"结束执行methodA");
    }
    public synchronized void methodB(){
        Thread t = Thread.currentThread();
        System.out.println(t.getName()+"开始执行methodB");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.getName()+"结束执行methodB");
    }
}
